<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>添加单个主要完单位弹出框</title>
<%@ include file="/common/meta.jsp"%>
<%@ include file="/common/taglibs.jsp"%>
<script type="text/javascript"
	src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>


<style type="text/css">
input {
	background-color: #FFFFFF;
	border: 1px solid #A1C0DC;
	height: 17px;
	padding: 2px 8px 0 3px;
}
</style>


<script type="text/javascript">
	var type = "${param.type}";
	var parentTable = parent.$("#" + "${param.parentTab}"); //父页面的表格
	var selectRadio = $(); //父页面选中的单选框
	var selectTr = $(); //父页面选中的行

	if (type == "edit") {
		selectRadio = parentTable.find(":radio:checked");
		selectTr = $(selectRadio.parents("tr").get(0));
	}

	$(function() {

		var submitpsn = selectTr.find("[name$='submit_psn']");//标示是否是申报人			
		/*var type = selectTr.find("[name$='nature_name']");
		
		alert(type.val()); 
		 */

		if (type == "edit") {

			$("input:not(:checkbox:radio:button),textarea").each(function() {

				var id = $(this).attr("name");
				if (id == null || id == "")
					return true;

				var parentObj = selectTr.find("[name$='/" + id + "']");

				//alert(parentObj.attr("name")+"   "+parentObj.val()+"    子页面"+id);

				var value = "";
				if (parentObj.is("span"))
					value = $.trim(parentObj.text());
				else
					value = parentObj.val();

				//if($(this).is("input"))//初始化input框 不包括radio

				$(this).val(value);
			});

			$(":radio").each(function() {//初始化radio框
				var name = $(this).attr("name");

				var value = $("[name='" + name + "_value']").val();
				if ($(this).val() == value)
					$(this).attr("checked", true);

			});

			//如果是申报人
			if (submitpsn.length > 0 && submitpsn.val() == "1") {
				$("input,select,a,img").each(

						function() {
							if (!$(this).attr("class")
									|| $(this).attr("class").indexOf(
											"notdisabled") == -1)
								$(this).attr("disabled", true);

							$("a").css("display", "none");
							$("#nature_name_tree_img").css("display", "none");

						});

				for (var i = 1; i < 9; i++) {
					$("#s" + i).remove();
				}

				$("#org_fax2").attr("disabled", false);
			}
		}

		$("#savePsn").click(function() {
			setTimeout(savePsn, 100);
		});
		

	});

	function savePsn() {
		//填写检查接口
		//saveResearch("researchTbl");
		validate($("#fragment-tab1"), "");

		if (!valResult()) {
			irisValShowMsg($("#savePsn"));
			return false;
		}
		//添加新行
		if (type == "add") {
			addNewRowDeal(parentTable);
		}

		$("textarea").each(
				function() {
					var val = $(this).val();
					val = val.replace(/&/g, "&amp;").replace(/</g, "&lt;")
							.replace(/>/g, "&gt;").replace(/\n/g, "<br/>")
							.replace(/\s/g, "&nbsp;").replace(/"/g, "&quot;");
					$("input[name='" + $(this).attr('name') + "_hidden']").val(
							val);
				});

		$("input:not(:checked:radio:button),textarea").each(
				function() {

					var id = $(this).attr("name");

					//alert(id);

					var parentObj = null;

					if (id == null || id == "")
						return true;

					//获得父页面的对象
					if (type == "add") {
						parentObj = parentTable.find("tr:last-child").find(
								"[name$='/" + id + "']");
					} else if (type == "edit") {
						parentObj = selectTr.find("[name$='/" + id + "']");
					}

					if (parentObj != null) {

						if (parentObj.is("span")) {
							parentObj.text($(this).val()); //将值写回父页面
						} else {

							parentObj.val($(this).val());

						}
					}

				});

		$(".wBox_popup").hide();
		alert("保存成功");

		window.setTimeout("parent.tb_remove()", 1000);
	}

	function loadAjaxSelect(selectId, url, params, varParm) {
		$.ajax({
			url : url,
			type : 'post',
			dataType : 'json',
			data : params,
			success : function(data) {

				for (var i = 0; i < data.length; i++) {
					var value = data[i].id;
					var text = data[i].name;
					$("#" + selectId).append(
							"<option value='"+value+"'>" + text + "</option>");

				}
				if (type == "edit") {//如果是修改，才需要初始化select框的值
					var selectValue = $("[name='" + selectId + "_value']")
							.val();
					$("#" + selectId + " option").each(function(i, obj) {
						if ($(obj).val() == selectValue) {
							setTimeout(function() {
								$(obj).attr("selected", true);
							}, 1);
						}
					});
				}
			}
		});
	}
</script>

</head>
<body>

	<div id="tabnav">
		<ul>
			<li class="down" id="tab1" onclick="changeTab(this.id)"><a
				href="#"><span>主要完成单位</span></a></li>
		</ul>
	</div>
	<div class="tab_box" id="fragment-tab1">
		<table class="" width="90%" border="0" cellpadding="0" cellspacing="1"
			style="line-height: 25px;" id="main_psn">
			<col style="width: 25%">
			<col style="width: 35%">
			<col style="width: 11%">
			<col style="width: 30%">
			<tr>
				<td align="right"><span id="s1" class="color_red">*</span>单位名称：</td>
				<td align="left">
					<input id="org_name" name="org_name" label="单位名称" type="text" style="width: 54%;" maxlength="100"
					class="required input_css input_width" />
				</td>
				<td align="right"><span id="s2" class="color_red">*</span>联系人：</td>
				<td align="left">
					<input id="contact_name" name="contact_name" label="联系人" type="text" style="width: 80%;"  maxlength="30"
					class="required input_css " />
				</td>
			</tr>
			<tr>
				<td align="right"><span id="s3" class="color_red">*</span>联系电话：</td>
				<td align="left">
					<input id="org_tel" name="org_tel" label="联系电话" type="text" style="width: 54%;"  maxlength="50"
					class="required input_css " /></td>
				<td align="right"><span class="color_red">*</span>传真：</td>
				<td align="left">
					<input id="fax2" name="fax2"  maxlength="50" label="传真" type="text" style="width: 80%;" class="required input_css notdisabled" />
				</td>
			</tr>
			<tr>
				<td align="right"><span id="s5" class="color_red">*</span>电子邮箱：</td>
				<td align="left">
					<input id="email" name="email" label="电子邮箱"  maxlength="50" type="text" style="width: 54%;" class="required input_css email" />
				</td>
				<td align="right"><span id="s6" class="color_red">*</span>邮政编码：</td>
				<td align="left">
					<input id="zip_code" name="zip_code" onfocus="InitInput.setInt(this,6,0,0)" maxlength="6" label="邮政编码" type="text"
					 style="width: 80%;" class="required input_css " />
				</td>
			</tr>
			<tr>
				<td align="right"><span id="s8" class="color_red">*</span>单位性质：</td>
				<td align="center">
					<cpt:tree key="nature_type" className="required " id="nature_name" cacheable="false" readonly="true" value=""
					 label="单位性质" showPattern="all" shieldPattern="0" onClick="initTreeValueExt" />
					<input type="hidden" name="nature_value" /> <!-- 上面的tree已经叫nature_name了，和父页面的对应项一样，所以就不用再搞个同名的hidden框了 <input type="hidden" name="nature_name" label="单位性质" /> -->
				</td>
			</tr>
			<tr>
				<td align="right"><span id="s7" class="color_red">*</span>通讯地址：</td>
				<td align="left" colspan="3">
					<input id="address" name="address" label="通讯地址" type="text" style="width:92%"  maxlength="100" class="required input_css " />
				</td>
				<td>&nbsp;</td><td>&nbsp;</td>
			</tr>
			<tr>
				<td align="right"><span class="color_red">*</span>主要贡献：<br />（限600字）
				</td>
				<td colspan="3">
					<textarea rows="10" style="width: 92%;" class="input_textarea required maxlength:600" name="main_contribution2" label="主要贡献"　></textarea> 
					<input type="hidden" name="main_contribution2_hidden" /></td>
			</tr>
			</div>
			<table width="100%" align="center">
				<col style="width: 25%">
				<col style="width: 25%">
				<col style="width: 25%">
				<col style="width: 25%">
				<tr>
					<td colspan="4" align="left"><input type="button"
						class="button_01 notdisabled" id="savePsn" value="保存">
						&nbsp; <input type="button" id="cancel"
						class="button_01 notdisabled" value="取消"
						onclick="parent.tb_remove();"></td>
				</tr>
			</table>
			<br />
</body>
</html>

<script type="text/javascript">
	function initTreeValueExt(treeId, treeNode) {

		if (( treeNode && treeNode.isParent)) {
			scmWarn("请选择具体的"+$("#" + treeId).attr("label"));
				$("#" + treeId).val("");
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val("");
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId+ "_value']").val("");
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val("");
				return false;
		}
			var str = treeNode.name;
			var obj = treeNode.parentNode;
			while (obj != null) {
				//str = obj.name + "-" + str;
				obj = obj.parentNode;
			}
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val(treeNode.id);
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId + "_value']").val(treeNode.id);
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val(str);
			$("#" + treeId).val(str);

	}

	//显示全名称路径
	function buildName(treeNode, params){
		var str = treeNode.name;
		var obj = treeNode.parentNode;
		while(obj!=null){
			//str =obj.name+"-"+str;
			obj = obj.parentNode;
		}
		return str;
	}
	
	/* 

	 function initTreeValueExt(treeId, treeNode) {

	 if (!(treeNode && (treeNode.level > 0 || !treeNode.isParent))) {
	 scmWarn($("#" + treeId).attr("label")
	 + messageTip.researchAreaInvalidDisciplineCode);
	 if (treeNode.level == 0) {
	 $("#" + treeId).val("");
	 $("#" + treeId).parents("td").find(
	 "[name$='" + treeId + "_code'],[id$='" + treeId
	 + "_code']").val("");
	 $("#" + treeId).parents("td").find(
	 "[name$='" + treeId + "_value'],[id$='" + treeId
	 + "_value']").val("");
	 $("#" + treeId).parents("td").find(
	 "[name$='" + treeId + "_name'],[id$='" + treeId
	 + "_name']").val("");
	 }

	 return false;
	 }

	 var str = treeNode.name;
	 var obj = treeNode.parentNode;
	 while (obj != null) {
	 str = obj.name + "-" + str;
	 obj = obj.parentNode;
	 }

	 $("#" + treeId).parents("td").find(
	 "[name$='" + treeId + "_code'],[id$='" + treeId + "_code']")
	 .val(treeNode.id);
	 $("#" + treeId).parents("td").find(
	 "[name$='" + treeId + "_value'],[id$='" + treeId + "_value']")
	 .val(treeNode.id);
	 $("#" + treeId).parents("td").find(
	 "[name$='" + treeId + "_name'],[id$='" + treeId + "_name']")
	 .val(str);

	 } */
</script>



